package com.mall.service.eshop;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mall.client.eshop.EshopService;
import com.mall.custom.dao.read.EshopReadMapper;
import com.mall.custom.dao.write.EshopWriteMapper;
import com.mall.pojo.Eshop;
import com.mall.pojo.EshopExample;
import com.mall.pojo.EshopExample.Criteria;
@Service
public class EshopServiceImpl implements EshopService {

	@Autowired
	private EshopReadMapper eshopReadMapper;
	@Autowired
	private EshopWriteMapper eshopWriteMapper;
	
	/**
	 * 根据id查找eshop
	 * @param id
	 * @return
	 */
	@Override
	public Eshop getEshopByEshopId(Long id) {
		if(id == null || id <= 0){
			return null;
		}
		return this.eshopReadMapper.selectByPrimaryKey(id);
	}

	/**
	 * 根据条件查找eshop集合
	 * @param eshopExample
	 * @return
	 */
	@Override
	public List<Eshop> getEshopListByEshopExample(EshopExample eshopExample) {
		// TODO Auto-generated method stub
		return this.eshopReadMapper.selectByExample(eshopExample);
	}

	/**
	 * 插入eshop
	 * @param eshop
	 * @return
	 */
	@Override
	public int insertEshopByEshop(Eshop eshop) {
		// TODO Auto-generated method stub
		return this.eshopWriteMapper.insert(eshop);
	}

	/**
	 * 修改eshop
	 * @param eshop
	 * @return
	 */
	@Override
	public int modifyEshopByEshop(Eshop eshop,Eshop existEshop) {
		if(existEshop != null){
			eshop.setId(existEshop.getId());
			eshop.setSaleEshopId(existEshop.getSaleEshopId());
			eshop.setGmtCreate(existEshop.getGmtCreate());
			eshop.setEshopCompanyId(existEshop.getEshopCompanyId());
			eshop.setTrademarkId(existEshop.getTrademarkId());
			eshop.setEshopSellerId(existEshop.getEshopSellerId());
		}
		return this.eshopWriteMapper.updateByPrimaryKey(eshop);
	}

	/**
	 * 删除eshop
	 * @param id
	 * @return
	 */
	@Override
	public int deleteEshopByEshopId(Long id) {
		// TODO Auto-generated method stub
		return this.eshopWriteMapper.deleteByPrimaryKey(id);
	}

	@Override
	public Eshop getEshopByEshopName(String eshopName) {
		EshopExample eshopExample = new EshopExample();
		Criteria criteria = eshopExample.createCriteria();
		criteria.andSaleEshopNameEqualTo(eshopName);
		List<Eshop> eshopList = this.eshopReadMapper.selectByExample(eshopExample);
		if(eshopList == null || eshopList.size() <= 0){
			return null;
		}
		return eshopList.get(0);
	}

	@Override
	public Eshop getEshopBySaleEshopId(Long saleEshopId) {
		if(saleEshopId == null || saleEshopId <= 0){
			return null;
		}
		EshopExample eshopExample = new EshopExample();
		Criteria criteria = eshopExample.createCriteria();
		criteria.andSaleEshopIdEqualTo(saleEshopId);
		List<Eshop> eshopList = this.eshopReadMapper.selectByExample(eshopExample);
		if(eshopList == null || eshopList.size() <= 0){
			return null;
		}
		return eshopList.get(0);
	}

	@Override
	public int getEshopCount(EshopExample eshopExample) {
		return this.eshopReadMapper.countByExample(eshopExample);
	}

}
